<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例</title>
    <script>
        // 判断出现最多的字符
        var str ='abcoefoxyozzopp';
        /* var arr=[];
        var count=0;
        for(var i=0;i<str.length;i++){
            count =0;
            // console.log(str[i]);
            var index= str.indexOf(str[i]);
            while (index!=-1) {
                count++;
                index++;
                index=str.indexOf(str[i],index);
            }
            arr.push(count);
            console.log(arr);
        }
        var num=Math.max(...arr);
        var idx=arr.indexOf(num);

        console.log(str.charAt(idx));  */

        var o={};
        
        // console.log(o['a']);
        for(var i=0;i<str.length;i++){

            if(o[str.charAt(i)]){
                o[str.charAt(i)]++;
            }else{
                o[str.charAt(i)]=1;
            }
        }
        console.log(o);

        var max=0;
        var ch='';
        for (const k in o) {
           if (max<o[k]) {
              var max= o[k];
              ch=k;
           }           
        }
        console.log(ch);
    </script>
</head>
<body>
    
</body>
</html>